<!DOCTYPE html>
<html>
<head>
    <title>Physics Graph: Velocity Distribution</title>
</head>
<body>
    <canvas id="physics-graph" width="400" height="300" style="border: 1px solid #d3d3d3;"></canvas>
    <script>
        const canvas = document.getElementById('physics-graph');
        const ctx = canvas.getContext('2d');

        // Parameters for drawing the coordinate system and graph
        const originX = 60;
        const originY = 260;
        const axisEndX = 360;
        const axisEndY = 40;

        // Relative scale of the points on the axes
        const v0_pixels = 100;
        const a_pixels = 120;

        // Key Point Coordinates based on the parameters
        const p1 = { x: originX + v0_pixels, y: originY - a_pixels };     // Corresponds to (v₀, a)
        const p2 = { x: originX + 2 * v0_pixels, y: originY - a_pixels }; // Corresponds to (2v₀, a)

        // --- Style setup ---
        ctx.strokeStyle = '#000';
        ctx.fillStyle = '#000';
        ctx.lineWidth = 1.5;
        // Use a serif font similar to the one in textbooks
        ctx.font = 'italic 18px "Times New Roman"';

        // --- Draw Axes ---
        ctx.beginPath();
        // X-axis (labeled 'v')
        ctx.moveTo(originX, originY);
        ctx.lineTo(axisEndX, originY);
        // X-axis arrowhead
        ctx.moveTo(axisEndX, originY);
        ctx.lineTo(axisEndX - 10, originY - 5);
        ctx.moveTo(axisEndX, originY);
        ctx.lineTo(axisEndX - 10, originY + 5);
        
        // Y-axis (labeled 'Nf(v)')
        ctx.moveTo(originX, originY);
        ctx.lineTo(originX, axisEndY);
        // Y-axis arrowhead
        ctx.moveTo(originX, axisEndY);
        ctx.lineTo(originX - 5, axisEndY + 10);
        ctx.moveTo(originX, axisEndY);
        ctx.lineTo(originX + 5, axisEndY + 10);
        ctx.stroke();

        // --- Draw the Graph Plot ---
        ctx.beginPath();
        ctx.lineWidth = 2; // Make the plot line slightly thicker than the axes
        ctx.moveTo(originX, originY); // Start at the origin O(0,0)
        ctx.lineTo(p1.x, p1.y);       // Line to (v₀, a)
        ctx.lineTo(p2.x, p2.y);       // Line to (2v₀, a)
        ctx.stroke();

        // --- Draw Dashed Helper Lines ---
        ctx.save();
        ctx.setLineDash([4, 4]);
        ctx.lineWidth = 1;
        ctx.strokeStyle = '#000';

        // Dashed line from (v₀, a) down to the x-axis
        ctx.beginPath();
        ctx.moveTo(p1.x, p1.y);
        ctx.lineTo(p1.x, originY);
        ctx.stroke();

        // Dashed line from (v₀, a) left to the y-axis
        ctx.beginPath();
        ctx.moveTo(p1.x, p1.y);
        ctx.lineTo(originX, p1.y);
        ctx.stroke();

        // Dashed line from (2v₀, a) down to the x-axis
        ctx.beginPath();
        ctx.moveTo(p2.x, p2.y);
        ctx.lineTo(p2.x, originY);
        ctx.stroke();
        
        ctx.restore(); // Restore to solid lines

        // --- Draw Labels ---
        // Origin 'O'
        ctx.fillText('O', originX - 20, originY + 15);
        
        // Axis Labels
        // 'Nf(v)' label for the Y-axis
        ctx.fillText('Nf(v)', originX + 20, axisEndY - 5);
        // 'v' label for the X-axis
        ctx.fillText('v', axisEndX + 10, originY + 5);
        
        // Tick Labels
        // 'a' on the Y-axis
        ctx.textAlign = 'right';
        ctx.fillText('a', originX - 8, p1.y + 5);
        
        // 'v₀' on the X-axis (handled as two parts for the subscript)
        ctx.textAlign = 'center';
        ctx.textBaseline = 'top';
        ctx.fillText('v', p1.x - 4, originY + 8);
        ctx.font = 'italic 12px "Times New Roman"';
        ctx.fillText('0', p1.x + 5, originY + 11);
        ctx.font = 'italic 18px "Times New Roman"'; // Reset font size

        // '2v₀' on the X-axis (handled as two parts for the subscript)
        ctx.fillText('2v', p2.x - 6, originY + 8);
        ctx.font = 'italic 12px "Times New Roman"';
        ctx.fillText('0', p2.x + 9, originY + 11);
        ctx.font = 'italic 18px "Times New Roman"'; // Reset font size
    </script>
</body>
</html>